package huizhi.net;

import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class SocketServer {
    public static void main(String[] args) throws Exception{

        System.out.println("我是SockerServer");
        //启动服务器，监听8888端口
        ServerSocket server = new ServerSocket(8888);
        //服务器待命，等待客户端连接，在套接字连接之前，都处于阻塞状态
        Socket accept = server.accept();
        //获取客户端输入字节流
        InputStream inputStream = accept.getInputStream();
        //buffer
        byte[] buf = new byte[1024];
        //读取到buf的字节数
        int readLength;
        while (-1 !=(readLength=inputStream.read(buf))){
            System.out.println(new String(buf,0,readLength));
        }
        inputStream.close();
        server.close();
    }
}
